﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TCM.Controllers
{
    public class MapStringController : Controller
    {
        private TCMContext db = new TCMContext();

        //
        // GET: /MapString/

        public ActionResult Index()
        {
            var mapstringbases = db.MAPSTRINGBASEs;
            return View(mapstringbases.ToList());
        }

        //
        // GET: /MapString/Details/5

        public ActionResult Details(Guid? id = null)
        {
            MAPSTRINGBASE mapstringbase = db.MAPSTRINGBASEs.Find(id);
            if (mapstringbase == null)
            {
                return HttpNotFound();
            }
            return View(mapstringbase);
        }

        //
        // GET: /MapString/Create

        public ActionResult Create()
        {
            ViewBag.MAPSTRINGID = new SelectList(db.Subjects, "SUBJECTED", "CODE");
            ViewBag.StatusID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE");
            return View();
        }

        //
        // POST: /MapString/Create

        [HttpPost]
        public ActionResult Create(MAPSTRINGBASE mapstringbase)
        {
            if (ModelState.IsValid)
            {
                mapstringbase.MAPSTRINGID = Guid.NewGuid();
                db.MAPSTRINGBASEs.Add(mapstringbase);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.MAPSTRINGID = new SelectList(db.Subjects, "SUBJECTED", "CODE", mapstringbase.MAPSTRINGID);
            ViewBag.StatusID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", mapstringbase.StatusID);
            return View(mapstringbase);
        }

        //
        // GET: /MapString/Edit/5

        public ActionResult Edit(Guid? id = null)
        {
            MAPSTRINGBASE mapstringbase = db.MAPSTRINGBASEs.Find(id);
            if (mapstringbase == null)
            {
                return HttpNotFound();
            }
            ViewBag.MAPSTRINGID = new SelectList(db.Subjects, "SUBJECTED", "CODE", mapstringbase.MAPSTRINGID);
            ViewBag.StatusID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", mapstringbase.StatusID);
            return View(mapstringbase);
        }

        //
        // POST: /MapString/Edit/5

        [HttpPost]
        public ActionResult Edit(MAPSTRINGBASE mapstringbase)
        {
            if (ModelState.IsValid)
            {
                db.Entry(mapstringbase).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.MAPSTRINGID = new SelectList(db.Subjects, "SUBJECTED", "CODE", mapstringbase.MAPSTRINGID);
            ViewBag.StatusID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", mapstringbase.StatusID);
            return View(mapstringbase);
        }

        //
        // GET: /MapString/Delete/5

        public ActionResult Delete(Guid? id = null)
        {
            MAPSTRINGBASE mapstringbase = db.MAPSTRINGBASEs.Find(id);
            if (mapstringbase == null)
            {
                return HttpNotFound();
            }
            return View(mapstringbase);
        }

        //
        // POST: /MapString/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(Guid id)
        {
            MAPSTRINGBASE mapstringbase = db.MAPSTRINGBASEs.Find(id);
            db.MAPSTRINGBASEs.Remove(mapstringbase);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}